<?php
class Myh_System_Info
{
	public function __construct()
	{
		$ns = new Zend_Session_Namespace('info');
	}
	public function createInfo($tblName)
	{
		$auth = Zend_Auth::getInstance();
		$infoAuth = $auth->getIdentity();
		$this->setMemberInfo($infoAuth, $tblName);
	}
	//Huy thong tin nguoi khi logout
	public function destroyInfo(){
		$ns = new Zend_Session_Namespace('info');
		$ns->unsetAll();
	}
	
	//Thiet lap thong tin cua User khi ho login
	public function setMemberInfo($infoAuth, $tblName){
		$db = Zend_Registry::get('connectDb');
		if($tblName == 'admin_user'){
			$select  = $db->select()
					  ->from($tblName)
					  ->where('user_id = ? ',$infoAuth->user_id,INTEGER);
			
		}else {
			$select  = $db->select()
					  ->from($tblName)
					  ->where('id = ? ',$infoAuth->id,INTEGER);
		}
		$result  = $db->fetchRow($select);
		$ns = new Zend_Session_Namespace('info');
		$ns->member = $result;
				  
					  
	}
	public function getMemberInfo($part = null){
		$ns = new Zend_Session_Namespace('info');
		$nsInfo = $ns->getIterator();
		
		if($part == null){
			$info = $nsInfo['member'];
		}else{
			$info = $nsInfo['member'];
			$info = $info[$part];
		}
		
		return $info;
	}
}